//
//  MCGoodsDetailViewController.swift
//  StoreManage
//
//  Created by MC on 2018/2/5.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCGoodsDetailViewController: MCPageViewController {
    
    var goodsId = 0
    
    var isOnShelves = 0
    
    private var navBarLineImageView : UIImageView? = nil
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navBarLineImageView?.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navBarLineImageView?.isHidden = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        baseSetting()
        
        initUI()
        
        sendNetworking()
    }
    
    // MARK: - System Delegate
    
    // MARK: - Custom Delegate
    
    // MARK: - Action
    @objc func leftItemClicked() {
        self.navigationController?.popViewController(animated: true)
    }
    
    @objc func rightItemClicked() {
        
        let para = [
            "goodsIdList" : [goodsId],
            ] as [String : Any]
        
        MCNetwork_post(url: JAVA_setGoodsOnShelves, para: para as [String : AnyObject], vc: self,hudSuperView: self.view,isHiddenTabbar: true, success: { (response) in
            MCHUD_text(message: "上架成功", view: self.view, delay: 1.2)
        }, dislike: { (response) in }) { (error) in }
    }

    // MARK: - Network
    func sendNetworking() {
        
    }
    
    // MARK: - Method
    func baseSetting() {
        self.title = "商品详情"
        
        self.navBarLineImageView = MCFindNavigationBarLine(view: (self.navigationController?.navigationBar)!)
        
        self.view.backgroundColor = UIColor.white
        
        navigationItem.leftBarButtonItem = MCSetBarButtonItem_image(#imageLiteral(resourceName: "Reuse_back"), target: self, selector: #selector(leftItemClicked),isLeft: true)

        
        
        if isOnShelves == 0 {
            
            navigationItem.rightBarButtonItem = MCSetBarButtonItem_text("上架", target: self, selector: #selector(rightItemClicked))            
        }
    }
    
    func initUI() {
        let titleArray = ["商品详情","规格详情"]
        
        let vc1 = MCGoodsDetailDescribeViewController()
        let vc2 = MCGoodsDetailSpecificationsViewController()
        
        vc1.goodsId = goodsId
        vc2.goodsId = goodsId

        
        
        
        let vcArray = [vc1,vc2]
        
        
        self.initWithTitleArray(titleArray, vcArray: vcArray, blockNormalColor: UIColor.MCGray_middle, blockSelectedColor: UIColor.MCMain, currentPage: 0)
    }
    
    // MARK: - Setter & Getter
}
